import { request } from '@umijs/max';
import qs from 'qs';

export async function get(
	url: string,
	params?: {
		keywords?: string;
		role?: string;
		city?: string;
		currentPage?: number;
		pageSize?: number;
	},
	options?: { [key: string]: any },
) {
	return request<any>(url, {
		method: 'GET',
		params: qs.parse(qs.stringify(params)),
		...(options || {}),
	});
}

export async function post(
	url: string,
	body?: any,
	options?: { [key: string]: any },
) {
	return request<API.Result_UserInfo_>(url, {
		method: 'POST',
		headers: {
			'Content-Type': 'application/json',
		},
		data: body,
		...(options || {}),
	});
}

// 根据用户的 token 获取用户信息
export async function getUserDetail(
	url: string,
	options?: { [key: string]: any },
) {
	return request<API.Result_UserInfo_>(url, {
		method: 'GET',
		...(options || {}),
	});
}

// 更新
export async function put(
	url: string,
	body?: any,
	options?: { [key: string]: any },
) {
	return request<any>(url, {
		method: 'PUT',
		headers: {
			'Content-Type': 'application/json',
		},
		data: body,
		...(options || {}),
	});
}

// 删除
export async function del(
	url: string,
	ids: number[],
	options?: { [key: string]: any },
) {
	return request<API.Result_string_>(url, {
		method: 'DELETE',
		data: ids,
		...(options || {}),
	});
}
